package com.ruoyi.member.controller;

import com.ruoyi.common.core.utils.JwtUtils;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.member.domain.BmWarehouse;
import com.ruoyi.member.domain.Member;
import com.ruoyi.member.service.ISupplierMemberService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author huang
 * @Date 2023/8/21 16:32
 * @PackageName: com.ruoyi.member.controller
 * @ClassName: SupplierMemberController
 * @Description:
 * @Version 1.0
 */
@RestController
@RequestMapping("/supplier/member")
public class SupplierMemberController {

    @Autowired
    private ISupplierMemberService supplierMemberService;

    @GetMapping("/getWarehouse")
    public BmWarehouse getWarehouse(@RequestHeader("Authorization") String authorization) {
        //拿到登陆者的用户id
        String claims = authorization.substring(7);
        String id = JwtUtils.getUserId(claims);
        return supplierMemberService.getWarehouse(Integer.valueOf(id));
    }

    @GetMapping("/getConnectMember")
    public List<Member> getConnectMember(@RequestHeader("Authorization") String authorization) {
        String claims = authorization.substring(7);
        String id = JwtUtils.getUserId(claims);
        return supplierMemberService.getConnectMember(Integer.valueOf(id));
    }

    @GetMapping("/getNotConnectMember")
    public List<Member> getNotConnectMember(@RequestHeader("Authorization") String authorization) {
        String claims = authorization.substring(7);
        String id = JwtUtils.getUserId(claims);
        return supplierMemberService.getNotConnectMember(Integer.valueOf(id));
    }

    @PostMapping("/addMember")
    public boolean addMember(@RequestBody Map<String,Object> map) {
        supplierMemberService.addMember(map);
        return true;
    }
}
